{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from torch import nn,optim\n",
    "from torch.autograd import Variable\n",
    "import torch\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAHHtJREFUeJzt3X+MXFd1B/Dv8WZCxgRlHLyUZBKzUCEHXNc7sIpcXFXEtHYUSJhCsUGhBZUqQi0Sjiy3G2HFcWQJU8s4rdqqcgGVKhbYJWGaEJBNa0eoUR2yZnZjjG0IiBiPI7IQbyB4Sdbr0z9m3uZ59t333uy8X/e970eyvLszu3v37eyZO+eee66oKoiIyB6L0h4AERH1hoGbiMgyDNxERJZh4CYisgwDNxGRZRi4iYgsw8BNRGQZBm4iIsswcBMRWeaKOL7o0qVLdWhoKI4vTUSUS8eOHfuFqg6GuW8sgXtoaAhjY2NxfGkiolwSkWfD3pepEiIiyzBwExFZhoGbiMgyDNxERJZh4CYisgwDNxGRZWIpByQiKopGs4VdB0/j3NQ0rq+UsWX9ctRr1Vi/Z+jALSIDAMYAtFT1ffENiYjIDo1mC/c8fBzTM7MAgNbUNO55+DgAxBq8e0mVfBrAybgG0mi2sGbnYbx59DGs2XkYjWYrrm9FRBSJXQdPzwVtx/TMLHYdPB3r9w0VuEXkBgDvBfCFOAbhPGu1pqahePVZi8GbiLLs3NR0Tx+PStgZ9wMA/hbApTgGkdazFhFRP66vlHv6eFQCA7eIvA/A86p6LOB+d4nImIiMTU5O9jSItJ61iIj6sWX9cpRLA5d9rFwawJb1y2P9vmFm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YxhLm53eP988AHDZMGhIdV1cu9A60c6hpewTAX3SqJVYDeNFJi6VJRN7orEuIyM1ox7Nf+n9W399TAHwRwElV/bzhbvFfryRXZA2rtM+gnQ8a7/xzVvqvB/DNrpXaH6I9O/tMAuP6U7SfOV8G8HMAB7vHhXZ1wETn34msjCul6/V6AP8D4Eed/6/tfHwEwBc6b78LwPHO9ToO4BMxjmfezw/gfrQnCABwFYD/7Dz+vgvgLXFfo5Dj+mznsTQB4AiAmxIY01cAPAdgpvPY+gSATwL4ZOd2AfDPnTEfh0+VVcLj+pTrWh0F8K4ExvSHaKc9nnbFrNuSvl7cOUlEZJnUUyVERNQbBm4iIsswcBMRWYaBm4jIMgzcRESWYeAmIrIMAzcRkWUYuImILPP/E8NInwSnLTsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x_data = np.linspace(-2, 2, 200)[:, np.newaxis]# 生成200个随机数\n",
    "noise = np.random.normal(0,0.02,x_data.shape)# 生成指定均值和标准差的高斯分布（正态分布）样本\n",
    "y_data = np.square(x_data) + noise\n",
    "\n",
    "plt.scatter(x_data,y_data)#话散点图\n",
    "plt.show()#显示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "#把numpy数据变成tensor\n",
    "x_data = torch.FloatTensor(x_data)\n",
    "y_data = torch.FloatTensor(y_data)\n",
    "input = Variable(x_data)\n",
    "target = Variable(y_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建神经网络模型\n",
    "# nn.Module是PyTorch中所有神经网络模块的基类\n",
    "class LinearRegression(nn.Module):\n",
    "    #定义网络结构，一般将网络中具有可学习参数的层放在__init__()中\n",
    "    def __init__(self):\n",
    "        # 初始化nn.module\n",
    "        super(LinearRegression, self).__init__()\n",
    "        self.fc1 = nn.Linear(1, 10)\n",
    "        #激活函数：这里选择tanh\n",
    "        self.tanh = nn.Tanh()\n",
    "        self.fc2 = nn.Linear(10, 1)\n",
    "    # 定义网络计算，输入x，根据nn.Linear自动生成的参数计算out\n",
    "    def forward(self, x):\n",
    "        x = self.fc1(x)\n",
    "        x = self.tanh(x)\n",
    "        out = self.fc2(x)\n",
    "        return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义模型\n",
    "model = LinearRegression()\n",
    "# 定义损失函数\n",
    "mse_loss = nn.MSELoss()\n",
    "# 定义优化器，用于调整权值，这里使用的是梯度下降法，第一个参数是模型的参数，第二个参数是学习率\n",
    "optimizer = optim.SGD(model.parameters(), lr=0.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:fc1.weight, param:Parameter containing:\n",
      "tensor([[-0.9894],\n",
      "        [ 0.2969],\n",
      "        [ 0.6785],\n",
      "        [-0.3242],\n",
      "        [-0.7209],\n",
      "        [ 0.6250],\n",
      "        [-0.0957],\n",
      "        [-0.0360],\n",
      "        [ 0.8208],\n",
      "        [ 0.5823]], requires_grad=True)\n",
      "name:fc1.bias, param:Parameter containing:\n",
      "tensor([-0.4199,  0.6989,  0.5410, -0.4620, -0.0891, -0.2574,  0.5672, -0.8256,\n",
      "        -0.6905,  0.9224], requires_grad=True)\n",
      "name:fc2.weight, param:Parameter containing:\n",
      "tensor([[-0.3022,  0.1483, -0.1954,  0.2539,  0.1852, -0.1621,  0.0799, -0.2680,\n",
      "         -0.1270,  0.0342]], requires_grad=True)\n",
      "name:fc2.bias, param:Parameter containing:\n",
      "tensor([-0.2327], requires_grad=True)\n"
     ]
    }
   ],
   "source": [
    "# 定义好模型后可以查看一下这个模型都有哪些参数\n",
    "for name, parameters in model.named_parameters():\n",
    "    print('name:{}, param:{}'.format(name, parameters))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 3.2538223266601562\n",
      "200 0.29970812797546387\n",
      "400 0.009647084400057793\n",
      "600 0.07099738717079163\n",
      "800 0.027263814583420753\n",
      "1000 0.012935899198055267\n"
     ]
    }
   ],
   "source": [
    "# 开始模型的训练\n",
    "for i in range(1001):\n",
    "    out = model(input)\n",
    "    # 计算loss\n",
    "    loss = mse_loss(out, target)\n",
    "    # 梯度清零\n",
    "    optimizer.zero_grad()\n",
    "    # 计算梯度\n",
    "    loss.backward()\n",
    "    # 调整权值\n",
    "    optimizer.step()\n",
    "    if i%200 == 0:\n",
    "        print(i,loss.item())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAIABJREFUeJzt3Xd4lMX2wPHvZFNIaAEDgqEEEJFOJBQFEVCKBYiKgoIFC/Zy9YeCiIByqVIEROXaBQWuIiLIRUTBSi/SEbBAaKGEUEJImd8f7+6bbSEbyPbzeZ487rw7SU7WcDI775kZpbVGCCFE8IjwdwBCCCGKRxK3EEIEGUncQggRZCRxCyFEkJHELYQQQUYStxBCBBlJ3EIIEWQkcQshRJCRxC2EEEEm0htfNCEhQSclJXnjSwshREhau3btEa11JU/6eiVxJyUlsWbNGm98aSGECElKqb897StTJUIIEWQkcQshRJCRxC2EEEFGErcQQgQZSdxCCBFkJHELIUSQ8Uo5oBBChIt569MYt3gH+zOyuCw+lgFd6pGanOjV7+lx4lZKWYA1QJrW+hbvhSSEEMFh3vo0Bs3dR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yl3YUxH7TB+mG7038Z8I3TndqdGKOzwT6I61aMv5zZwCFgsXNcGNUBG60fWwIlLj+9XpcAS4E/rP+taL2eArxrfXwNsMn6em0CHvRiPC4/P/AqxgABoBTwX+vv3yqgtrdfIw/jGmX9XdoI/ABc6YOYPgMOADnW360HgUeBR63PK+BNa8ybOE+VlY/jetLutVoBXOODmNpiTHv8bpezbvL16yUrJ4UQIsj4fapECCFE8UjiFkKIICOJWwghgowkbiGECDKSuIUQIshI4hZCiCAjiVsIIYKMJG4hhAgy/w+asEGXaaf8SwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 测试\n",
    "y_pred = model(input)\n",
    "plt.scatter(x_data, y_data)\n",
    "plt.plot(x_data, y_pred.data.numpy(), 'r-', lw = 3)\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
